import axios from './axios';


/**
 * 
 * @param {第几页} page 
 * @param {一页几条} limit 
 * @param {文件夹的id} folderId 
 * @returns 
 */
export async function findFiles(page, limit, folderId) {
    return await axios.get(`/api/files/findFiles?page=${page}&limit=${limit}&folderId=${folderId}`)
}

/**
 * 
 * @param {文件夹id} folderId 
 * @returns 返回所有文件夹
 */
export async function findFilesAllCount(folderId) {
    return await axios.get(`/api/files/findFilesAllCount?folderId=${folderId}`);
}

/**
 * 查询单个文件
 * @param {文件夹id} folderId 
 * @param {文件id} fileId 
 */
export async function findFile(folderId, fileId) {
    return await axios.get(`/api/files/findFile?folderId=${folderId}&fileId=${fileId}`);
}

/**
 * 
 * @param {文件名字} name 
 * @param {文件内容} content 
 * @param {文件类型} type 
 * @param {文件夹id} folderId 属于哪个文件夹下面的 
 */
export async function createFiles(name, content, type, folderId) {
    return await axios.post('/api/files/createFiles', {
        name, content, type, folderId
    })
}

/**
 * 更新单个文件
 * @param {文件夹id} folderId 
 * @param {文件id} fileId 
 * @param {名字} name 
 * @param {内容} content 
 * @returns 
 */
export async function updateFile(folderId, fileId, name, content) {
    return await axios.post('/api/files/updateFile', {
        folderId, fileId, name, content
    });
}

export async function deleteFile(fileId) {
    return await axios.get(`/api/files/deleteFile?fileId=${fileId}`);
}